#include "serverconfig.h"
#include <QCoreApplication>
#include <QDir>

ServerConfig::ServerConfig()
{
    m_rootDir = QCoreApplication::applicationDirPath();
}

ServerConfig::~ServerConfig()
{

}

void ServerConfig::setAnonymousEnable(bool enable)
{
    m_anonymousEnable = enable;
}

bool ServerConfig::anonymousEnable() const
{
    return m_anonymousEnable;
}

void ServerConfig::addUser(const QString &username, const QString &password)
{
    m_users.insert(username, password);
}

bool ServerConfig::verifyUser(const QString &username, const QString &password) const
{
    auto pos = m_users.find(username);
    if (pos != m_users.end() && pos.value() == password)
        return true;

    return false;
}

void ServerConfig::setRootDirectory(const QString &rootDir)
{
    m_rootDir = QDir(rootDir).absolutePath();
}

QString ServerConfig::rootDirectory() const
{
    return m_rootDir;
}
